package com.flitsneak.kafka.producer;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author flitsneak
 * @email flitsneak@gmail.com
 * @date 2022/8/10 14:59
 * @description
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/kafka")
public class KafkaProducer {

    private final KafkaTemplate<String,String> kafkaTemplate;

    @GetMapping("/sendMessage")
    public String sendMessage() {
        String msg = "hello!";
        kafkaTemplate.send("topic1",msg);
        return "success!";
    }
}
